/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#ifndef PLRADIXTREEVOID_H
#define PLRADIXTREEVOID_H

#include <tools/PLRadixTreeNode.h>
#include <cstddef>
#include <stdio.h>
#include <stdlib.h>

namespace PLSDK {

    template<class E>
    class PLRadixTree;

    /**
     * The base implementation of the radix tree.
     */
    template<>
    class PLRadixTree<void*> {
    public:
        /**
         * The default constructor, does nothing.
         */
        PLRadixTree();
        /**
         * The copy-constructor
         *
         * @param x the reference object to copy.
         */
        PLRadixTree(const PLRadixTree<void*> &x);
        /**
         * The destructor, deallocates memory.
         */
        ~PLRadixTree();
        /**
         * The assignment operator.
         *
         * @param x the object that should be copied.
         */
        PLRadixTree &operator = (const PLRadixTree &x);
        /**
         * Get the number of elements in the Tree.
         *
         * @return the number of elements in the Tree.
         */
        size_t count() const;
        /**
         * Add an element to the Tree.
         *
         * @param key the key.
         * @param value the element.
         */
        void insert(const char *key, void *value);
        /**
         * Attempts to find an element with the given key.
         *
         * @param key the key.
         * @return the element found, or NULL if not found.
         */
        void *lookup(const char *key);
        /**
         * Attempts to remove an element with the given key.
         *
         * @param key the key.
         */
        void remove(const char *key);
        /**
         * Clear the tree.
         */
        void clear();
    private:
        // Internal function to create a copy of a subtree.
        PLRadixTreeNode *cloneNode(PLRadixTreeNode *node, PLRadixTreeNode *parent);
        // Number of items in the tree.
        int m_nItems;
        // The tree's root.
        PLRadixTreeNode *m_pRoot;
    };

}

#endif
